import { customAlphabet } from 'nanoid'

const nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', 10)

export function generateKey(): string {
  return nanoid()
}

/**
 * 枚举数组查询
 * @param list
 * @param key
 * @returns lable
 */
export function list2Map(list: any[], key?: string) {
  const config = {
    key: key || 'id',
  }

  const map = {}

  for (const item of list) {
    map[item[config.key]] = item
  }

  return map
}
